﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<z.m.db.Order_Detail>" %>

<% if (ViewData["type"] == "header") {%>
<tr>
	<td rowspan="2"><%: Html.LabelFor(m=>m.ID) %></td>
	<td colspan="4">Product</td>
	<td rowspan="2">Quantity</td>
	<td rowspan="2">Total</td>
	<td rowspan="2" colspan="99">Controll</td>
</tr>
<tr>
	<td colspan="2"><%:Html.LabelFor(m=>m.Product.ID) %></td>
	<td><%:Html.LabelFor(m=>m.Product.Name) %></td>
	<td><%:Html.LabelFor(m=>m.Product.Price) %></td>
</tr>
<%} else if (ViewData["type"] == null) {
		bool _readonly=false;
		object att = new {
			@class = "number"
		};
		if (Model.Order != null) {
			if (!User.IsInRole("Admin") && Model.Order.Pay_Date.HasValue) {
				_readonly= true;
				att = new {
					@class = "number",
					@readonly = "true"
				};
			}
		}
%>
<tr id="or_dt<%:Model.ID%>" data-id="<%:Model.ID%>">
	<td>
		<div class="img">
			<img src="<%:Url.Content("~/Content/img/p/"+Model.Product_ID+".jpg") %>" />
		</div>
		<input name="ID" readonly="true" type="text" value="<%:Model.ID %>" />
	</td>
	<td>
		<%:Html.TextBoxFor(m => m.Order_ID, new { @readonly=true,@class="collapse" })%>
		<%:Html.TextBoxFor(m => m.Product_ID, new { @readonly=true,@class="number" })%>
	</td>
	<td>
		<%
	  if (Model.Order != null) {
		  if (User.IsInRole("Admin") || !Model.Order.Pay_Date.HasValue) { %>
		<input value="Product" type="button" onclick="
	elPID=el('#or_dt<%:Model.ID%>	[name=\'Product_ID\']');
	openPID();" />
		<%}
	  } else { %>
		<input value="Product" type="button" onclick="
	elPID=el('#or_dt<%:Model.ID%>	[name=\'Product_ID\']');
	openPID();" />
		<%} %>
	</td>
	<td>
		<%:Html.TextBoxFor(m => m.Product.Name, new {@readonly=true })%>
	</td>
	<td>
		<%:Html.TextBoxFor(m=>m.Product.Price, new {@readonly=true,@class="number" }) %>
	</td>
	<td>
		<%:Html.TextBoxFor(m=>m.Quantity, att) %>
		<%:Html.ValidationMessageFor(m=>m.Quantity) %>
	</td>
	<td>
		<%:Html.TextBox("Total",Model.Unit_Price*Model.Quantity,"{0:$#,##0}", new {@readonly=true,@class="number"}) %>
	</td>
	<% if (!_readonly) { %>
	<td>
		<input type="button" value="<%:Model.ID==0?"Add":"Save" %>" onclick='ajaxTrSubmit(event);' <%:Model.ID==0&&Model.Product_ID==0?"disabled":"" %>/>
	</td>
	<td>
		<input type="button" value="Delete" onclick='ajaxTrBtn(event,"Delete");' />
	</td>
	<%}%>
</tr>
<%} else {%>
<%} %>